package recursion;

import java.util.Scanner;

/**
 * @Author wangtengyu
 * @Create 2018-03-23-14:34
 * 递归-阶乘  负数没有阶乘
 */
public class Fatorial {

    public static int getFatorial(int n){
        if(n>=0){
            if(n==0){
                return 1;
            }
            return n*getFatorial(n-1);

        }else{
            return -1;
        }
    }


    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入要求阶乘的数字:");
        int num=scanner.nextInt();
        System.out.println(num+"!的结果为");
        System.out.println(getFatorial(num));
    }




}
